import time

from selenium.webdriver.common.by import By

from common.Utills import BlogDriver
#博客首页

class BlogList:
    url=''
    driver=''
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
    #测试首页（登录情况下）
    def ListTestByLogin(self):
        #通过文章标题元素个数得到文章个数
        tme = len(self.driver.find_elements(By.XPATH,'/html/body/div[2]/div[2]/div'))
        blogNum = self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)").text
        if(blogNum!=tme):
            print("用户头像下方文章数量有误")
            BlogDriver.getScreeShont()
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > a").click()
        if self.driver.current_url == "https://gitee.com/bubble-fish666/class-java45":
            print("GitHub成功")
            BlogDriver.getScreeShont()
            self.driver.back()
        else:
            print("GitHub失败")
            BlogDriver.getScreeShont()
        #测试博客标题是否存在
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.right > div:nth-child(1) > div.title')
        if elements:
            print("标题存在")
        else:
            print("标题不存在")
        #测试博客内容是否存在
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.right > div:nth-child(1) > div.desc')
        if elements:
            print("博客内容存在")
        else:
            print("博客内容不存在")
        #测试博客按钮是否存在
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.right > div:nth-child(1) > a')
        if elements:
            print("按钮存在")
        else:
            print("按钮不存在")
        #个人信息-检查昵称是否存在
        elements = self.driver.find_elements(By.CSS_SELECTOR,'body > div.container > div.left > div > h3')
        if elements:
            print("昵称存在")
        else:
            print("昵称不存在")
        #添加截图
        BlogDriver.getScreeShont()
